package 数据库和网络;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class serveSocket {
    static final int PORT=20222;
    Socket thatSocket;
    ServerSocket sevrSocket;
    BufferedWriter infoSender;
    BufferedReader commandReader;
    PrintWriter waiter;

    public void start(){
        try {
            sevrSocket=new ServerSocket(PORT);
            thatSocket=sevrSocket.accept();
            infoSender=new BufferedWriter(new OutputStreamWriter(thatSocket.getOutputStream()));
            commandReader=new BufferedReader(new InputStreamReader(thatSocket.getInputStream()));
            waiter=new PrintWriter(infoSender,true);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void close(){
        try {
            this.waiter.close();
            this.infoSender.close();
            this.commandReader.close();
            this.thatSocket.close();
            this.sevrSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ;

    }

}
